﻿using RestSharp;
using Ymatou.ServiceCenter;
using Ymatou.User.Dto.Auth;
using YmtAuth.AppService;
using YmtAuth.Dto;
using YmtSystem.CrossCutting;
using ResetService = ServiceStack.Service;
using ServiceStack;

namespace YmtAuth.Web.Handlerv2
{
    public class UserTokenDtoHandler : ResetService
    {
        private ITokenAppService TokenAppService { get { return LocalServiceLocator.GetService<ITokenAppService>(); } }
        private IAuthAppService AuthAppService { get { return LocalServiceLocator.GetService<IAuthAppService>(); } }
        
        //生成用户token
        [ServiceRegister("/json/reply/UserTokenDto", Method.POST)]
        public object Post(UserTokenDto request)
        {
            return TokenAppService.CreateUserToken(request);
        }
        //移除用户token
        [ServiceRegister("/json/reply/UserRemoveTokenRequestDto", Method.POST)]
        public object Post(UserRemoveTokenRequestDto request)
        {
            YmatouLoggingService.Debug("【删除token】 RemoveToken, request parameters:{0}", request.ToJson());
            
            return TokenAppService.RemoveToken(request);
        }

        //移除用户token
        [ServiceRegister("/json/reply/UserRemoveTokenRequestDto", Method.GET)]
        public object Get(UserRemoveTokenRequestDto request)
        {
            YmatouLoggingService.Debug("【删除token】 RemoveToken, request parameters:{0}", request.ToJson());
            
            return TokenAppService.RemoveToken(request);
        }

        //用户退出，删除token
        [ServiceRegister("/json/reply/SSOTokenDto", Method.POST)]
        public object Post(SSOTokenDto request)
        {
            return AuthAppService.Logout(request);
        }
    }
}